import {
  FrontPageParams,
  StandardizePageParams,
  StdPageParams,
  StdPageResult,
  StdResponse,
} from '/@/api/model/baseModel';
import { defHttp } from '/@/utils/http/axios';
import { AlarmLvList, GetAlarmLogsReq, Rule } from '/@/api/monitor/entity/entity';

export function listRules(params: FrontPageParams | StdPageParams) {
  return defHttp.get<StdPageResult<Rule>>({
    url: '/monitor/rules',
    params: StandardizePageParams(params),
  });
}

export function deleteRule(id: number) {
  return defHttp.delete<StdResponse>({
    url: `/monitor/rule/${id}`,
  });
}

export function getRule(id: number) {
  return defHttp.get<Rule>({
    url: `/monitor/rule/${id}`,
  });
}

export function getAlarmLvs() {
  return defHttp.get<AlarmLvList>({
    url: `/monitor/rule/alarm_level`,
  });
}

export function editRule(rl: Rule) {
  return defHttp.put<StdResponse>({
    url: `/monitor/rule`,
    data: rl,
  });
}

export function addRule(rl: Rule) {
  return defHttp.post<StdResponse>({
    url: `/monitor/rule`,
    data: rl,
  });
}

export function getAlarmLogs(req: GetAlarmLogsReq) {
  return defHttp.get<StdResponse>({
    url: `/monitor/rule/alarm_logs/chart`,
    params: req,
  });
}

export function getAlarmLogsCount(req: GetAlarmLogsReq) {
  return defHttp.get<StdResponse>({
    url: `/monitor/rule/alarm_logs/count`,
    params: req,
  });
}

export function getAlarmLogsSrc(req: GetAlarmLogsReq) {
  return defHttp.get<StdResponse>({
    url: `/monitor/rule/alarm_logs/source`,
    params: req,
  });
}

export function getAlarmLogsRadar(req: GetAlarmLogsReq) {
  return defHttp.get<StdResponse>({
    url: `/monitor/rule/alarm_logs/radar`,
    params: req,
  });
}

export function getStatus(req: GetAlarmLogsReq) {
  return defHttp.get<StdResponse<number>>({
    url: `/monitor/rule/status`,
    params: req,
  });
}
